package com.ly.cloud.controller;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.plugins.Page;
import com.ly.cloud.common.mybatisplus.plugins.PageInfo;
import com.ly.cloud.dto.TeacherDto;
import com.ly.cloud.service.TeacherService;
import com.ly.cloud.vo.TeacherDetailVo;
import com.ly.cloud.vo.TeacherDmjVo;
import com.ly.cloud.vo.TeacherSimpleVo;
import com.ly.cloud.vo.TeacherVo;
import com.ly.cloud.web.utils.WebResponse;


/**
 * 师资管理Controller
 * @author caihuihai
 * @date 2018年12月13日 下午3:23:27
 */
@RestController
@RequestMapping("/teacher")
public class TeacherController {
	
	@Resource
	private TeacherService teacherService;
	
	/**
	 * 分页查询教职工列表
	 * @return
	 */
	@RequestMapping(value = "/queryList", method = RequestMethod.GET)
	public WebResponse<PageInfo<TeacherVo>> queryPageList(@RequestParam int pageNum, @RequestParam int pageSize,TeacherDto dto) {
		Page<TeacherVo> page = teacherService.selectPage(new Page<TeacherVo>(pageNum, pageSize),dto);
		return new WebResponse<PageInfo<TeacherVo>>().success(PageInfo.toPageInfo(page));
	}
	
	/**
	 * 新增或修改教职工
	 * @param dto
	 * @return
	 */
	@RequestMapping(value = "/submitJzg", method = RequestMethod.POST)
	public WebResponse<Boolean> submitJzg(@RequestHeader(required=false,value="loginUserName")String loginUserName,@RequestBody TeacherDto dto) {
		boolean rs = teacherService.submitJzg(dto,loginUserName);
		return new WebResponse<Boolean>().success(rs);
	}
	
	/**
	 * 根据工号查询教职工详细信息
	 * @return
	 */
	@RequestMapping(value = "/findTeacherByGh/{gh}", method = RequestMethod.GET)
	public WebResponse<TeacherDetailVo> findTeacherByGh(@PathVariable("gh") String gh) {
		TeacherDetailVo vo = teacherService.findTeacherByGh(gh);
		return new WebResponse<TeacherDetailVo>().success(vo);
	}
	
	/**
	 * 删除单个教职工
	 * @return
	 */
	@RequestMapping(value = "/deleteByGh/{gh}", method = RequestMethod.GET)
	public WebResponse<Boolean> deleteByGh(@PathVariable("gh") String gh) {
		boolean rs = teacherService.deleteByGh(gh);
		return new WebResponse<Boolean>().success(rs);
	}
	
	/**
	 * 批量删除教职工
	 * @param ids
	 * @return
	 */
	@RequestMapping(value = "/deleteByGhs", method = RequestMethod.POST)
	public WebResponse<Boolean> deleteByGhs(@RequestBody List<String> ghs) {
		boolean rs = teacherService.deleteByGhs(ghs);
		return new WebResponse<Boolean>().success(rs);
	}
	
	/**
     * 查询教职工列表（下拉）
     */
    @RequestMapping(value = "/findTeachList", method = RequestMethod.GET)
    public WebResponse<List<TeacherSimpleVo>> findTeachList(){
        List<TeacherSimpleVo> list = teacherService.findTeachList();
        return new WebResponse<List<TeacherSimpleVo>>().success(list) ;
    }
    
    
    /**
     * 查询教职工新增页面的下拉值
     */
    @RequestMapping(value = "/queryDmjList", method = RequestMethod.GET)
    public WebResponse<List<TeacherDmjVo>> queryDmjList(){
        List<TeacherDmjVo> list = teacherService.queryDmjList();
        return new WebResponse<List<TeacherDmjVo>>().success(list) ;
    }

}
